/*******************************************************************************
 * Copyright (c) 2008 Bastien Amar.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Bastien Amar - initial API and implementation
 *******************************************************************************/

package fr.irit.etracetool.simpleemf;

import java.io.File;
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import fr.irit.etracetool.etrace.ETrace;

public class Persistent {

	public static void SaveTrace(ETrace trace, String path) {
		ResourceSet resourceSet = new ResourceSetImpl();
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", 
				new XMIResourceFactoryImpl());
		Resource resource = resourceSet.createResource(URI.createURI(path));
		resource.getContents().add(trace);
		try {
			resource.save(null);
		} catch (IOException e) {
			System.err.println("IOException during SaveTrace ! " + e.getCause());
			e.printStackTrace();
		}
	}
	
	public static void SaveTrace(ETrace trace, URI tracePath) {
		ResourceSet resourceSet = new ResourceSetImpl();
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", 
				new XMIResourceFactoryImpl());
		Resource resource = resourceSet.createResource(tracePath);
		resource.getContents().add(trace);
		try {
			resource.save(null);
		} catch (IOException e) {
			System.err.println("IOException during SaveTrace ! " + e.getCause());
			e.printStackTrace();
		}
	}

}
